﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Resources;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Foundation.Markup
{
    public class Picture : MarkupExtension
    {
        public static readonly List<ResourceManager> Managers = new List<ResourceManager>();

        public Picture()
        {
            Width = Height = 16;
        }

        public ImageSource Key { get; set; }
        public double Width { get; set; }
        public double Height { get; set; }

        //public object ProvideValue(IServiceProvider serviceProvider)
        //{
        //    var value = Managers.Select(m => m.GetObject(Key)).LastOrDefault(v => v != null) as Image;
        //    if (value == null) return null;
        //    if (double.IsNaN(Height)) Height = value.Height;
        //    else value.Height = Height;
        //    if (double.IsNaN(Width)) Width = value.Width;
        //    else value.Width = Width;
        //    return value;
        //}

        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return new Image {Source = Key, Width = Width, Height = Height};
            //Key = Key.Contains(".") ? Key : Key + ".png";
            //return ProvideValue(null);
        }
    }
}
